package com.common.exception;

import com.common.enums.ApiResult;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常处理器
 */
@RestControllerAdvice
public class CommonExceptionHandler {

    @ExceptionHandler(value = ErrorException.class)
    public ApiResult errorHandler(ErrorException exception) {
        exception.printStackTrace();
        return ApiResult.failure(exception.getMessage());
    }

    @ExceptionHandler(value = Exception.class)
    public ApiResult commonHandler(Exception exception) {
        exception.printStackTrace();
        return ApiResult.failure("操作失败");
    }
}
